package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     * @param addressBook
     * @return
     */
    void add(AddressBook addressBook);
    /**
     * 查询用户所有的地址
     * @return
     */
    @Select("select * from address_book where  user_id = #{currentId}")
    List<AddressBook> selectAll(Long currentId);


    /**
     * 更新数据
     * @param a
     */
    void update(AddressBook a);

    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
    /**
     * 把该用户的全部地址设为默认
     * @param addressBook
     */

    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);

    /**
     * 查询默认地址
     * @param addressBook
     * @return
     */
    List<AddressBook> selectDeAddress(AddressBook addressBook);

    /**
     * 根据id查地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook selectById(Integer id);
}
